define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'sales/index',
        export_url: 'sales/export',
        detail_url: 'sales/detail',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh', 'export'],
                cols: [[
                    {field: 'is_today', hide: true, search: false},
                    {field: 'id', title: 'id', hide: true, search: false},
                    {field: 'true_name', title: '员工', width: 100},
                    {field: 'name', title: '客户', search: false},
                    {field: 'phone', title: '手机号', hide: true, search: false},
                    {field: 'type', search: 'select', selectList: ["定制","现有"], title: '项目类型', width: 100},
                    {field: 'project_status', search: 'select', selectList: ["首次对接","二次跟踪","多次跟踪","已交易"], title: '项目状态'},
                    {field: 'status', search: false, title: '状态', templet: function (d) {
                            if (d.status == 0){
                                return '<div class="layui-table-cell" style="color: green;">对接中</div>';
                            }
                            return '<div class="layui-table-cell" style="color: red;">已失败</div>';
                        }
                    },
                    {field: 'last_time', title: '最近追销', search: false, templet: function (d) {
                            if (d.is_today == 0){
                                return '<div class="layui-table-cell" style="color: red;">'+ d.last_time +'</div>';
                            }
                            return '<div class="layui-table-cell">'+ d.last_time +'</div>';
                        }
                    },
                    {field: 'create_time', title: '创建时间',search: 'range'},
                    {
                        width: 120,
                        title: '操作',
                        templet: ea.table.tool,
                        operat: [
                            [{
                                text: '追销记录',
                                url: init.detail_url,
                                method: 'open',
                                auth: 'detail',
                                class: 'layui-btn layui-btn-xs layui-btn-success',
                                extend: 'data-full="true"',
                            }]
                        ]
                    }
                ]],
            });
            ea.listen();
        },
        index2: function () {
            ea.table.render({
                init: {
                    table_elem: '#currentTable',
                    table_render_id: 'currentTableRenderId',
                    index_url: 'sales/index2',
                },
                toolbar: ['refresh', 'export'],
                cols: [[
                    {field: 'is_today', hide: true, search: false},
                    {field: 'id', title: 'id', hide: true, search: false},
                    {field: 'true_name', title: '员工', width: 100},
                    {field: 'name', title: '客户', search: false, width: 100},
                    {field: 'phone', title: '手机号', hide: true, search: false},
                    {field: 'type', search: 'select', selectList: ["定制","现有"], title: '项目类型', width: 100},
                    {field: 'project_status', search: 'select', selectList: ["首次对接","二次跟踪","多次跟踪","已交易"], title: '项目状态'},
                    {field: 'status', search: false, title: '状态', templet: function (d) {
                            if (d.status == 0){
                                return '<div class="layui-table-cell" style="color: green;">对接中</div>';
                            }
                            return '<div class="layui-table-cell" style="color: red;">已失败</div>';
                        }
                    },
                    {field: 'last_time', title: '最近追销', search: false, templet: function (d) {
                            if (d.is_today == 0){
                                return '<div class="layui-table-cell" style="color: red;">'+ d.last_time +'</div>';
                            }
                            return '<div class="layui-table-cell">'+ d.last_time +'</div>';
                        }
                    },
                    {field: 'create_time', title: '创建时间',search: 'range'},
                    {
                        width: 120,
                        title: '操作',
                        templet: ea.table.tool,
                        operat: [
                            [{
                                text: '追销记录',
                                url: init.detail_url,
                                method: 'open',
                                auth: 'detail',
                                class: 'layui-btn layui-btn-xs layui-btn-success',
                                extend: 'data-full="true"',
                            }]
                        ]
                    }
                ]],
            });
            ea.listen();
        },
        detail: function () {
            ea.table.render({
                init: {
                    table_elem: '#currentTable',
                    table_render_id: 'currentTableRenderId',
                    index_url: id ? 'sales/detail?id=' + id : 'sales/detail',
                },
                page: false,
                search: false,
                toolbar: [],
                cols: [[
                    {field: 'url', title: '追销证明', templet: ea.table.image},
                    {field: 'create_time', title: '追销时间'},
                ]],
            });
            ea.listen();
        },
    };
    return Controller;
});